﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using BLL;

namespace CorporateGymManagementSystem
{

    public delegate void UpdateMedicalApprovalEventHandler();

    /// <summary>
    /// Interaction logic for UpdateTraineeMedicalApprovalWindow.xaml
    /// </summary>
    /// 
    public partial class UpdateTraineeMedicalApprovalWindow : Window
    {
        public event UpdateMedicalApprovalEventHandler MedicalApprovalUpdated;
        private MedicalApproval m_MedicalApproval;
        public UpdateTraineeMedicalApprovalWindow(MedicalApproval i_MedicalApproval)
        {
            m_MedicalApproval = i_MedicalApproval;
            InitializeComponent();
        }

        private void submitExpirationDateButton_Click(object sender, RoutedEventArgs e)
        {
            resultLabel.Content = string.Empty;
            DateTime newExpirationDate = DateTime.Now;
            bool isAllValid = true;
            if (MedicalApprovalExpirationDatePicker.SelectedDate.HasValue == false)
            {
                isAllValid = false;
                MedicalApprovalExpirationDatePicker.Background = Brushes.Pink;
            }
            else
            {
                MedicalApprovalExpirationDatePicker.Background = Brushes.White;
                newExpirationDate = MedicalApprovalExpirationDatePicker.SelectedDate.Value;
            }

            m_MedicalApproval.ExpirationDate = newExpirationDate;
            if (isAllValid)
            {
                bool updateResult = MedicalApprovalManager.Instance.UpdateMedicalApproval(m_MedicalApproval);
                if (updateResult == true)
                {
                    resultLabel.Content = "Update Succeeded!";
                    MedicalApprovalUpdated();
                    resultLabel.Foreground = Brushes.Green;
                }
                else
                {
                    resultLabel.Content = "Error!";
                    resultLabel.Foreground = Brushes.Crimson;
                }
            }
            else
            {
                resultLabel.Content = "Please choose a date!";
                resultLabel.Foreground = Brushes.Crimson;
            }
        }
    }
}
